<?php

use yii\db\Migration;

/**
 * Class m221109_073244_rbac_contract_status
 */
class m221109_073244_rbac_contract_status extends Migration
{
    /**
     * {@inheritdoc}
     */
    public function safeUp()
    {
        $auth = Yii::$app->authManager;

        $permissionCreate = $auth->createPermission('createContractStatus');
        $auth->add($permissionCreate);

        $permissionUpdate = $auth->createPermission('updateContractStatus');
        $auth->add($permissionUpdate);

        $permissionDelete = $auth->createPermission('deleteContractStatus');
        $auth->add($permissionDelete);

        $permissionBrowse = $auth->createPermission('browseContractStatus');
        $auth->add($permissionBrowse);

        $userRole = $auth->createRole('contractStatusUser');
        $auth->add($userRole);

        $managerRole = $auth->createRole('contractStatusManager');
        $auth->add($managerRole);

        $auth->addChild($userRole, $permissionBrowse);

        $auth->addChild($managerRole, $permissionCreate);
        $auth->addChild($managerRole, $permissionUpdate);
        $auth->addChild($managerRole, $permissionDelete);
        $auth->addChild($managerRole, $permissionBrowse);
    }

    /**
     * {@inheritdoc}
     */
    public function safeDown()
    {
        $auth = Yii::$app->authManager;

        $auth->remove($auth->getPermission('createContractStatus'));
        $auth->remove($auth->getPermission('updateContractStatus'));
        $auth->remove($auth->getPermission('deleteContractStatus'));
        $auth->remove($auth->getPermission('browseContractStatus'));
        $auth->remove($auth->getRole('contractStatusUser'));
        $auth->remove($auth->getRole('contractStatusManager'));
    }
}
